package Functii.Trigonometrice;
import Functii.*;
import Operator.*;

public class Ctg extends Functie{

	public static double calcul(double aux1){
		return 1/Math.tan(aux1);
	}
	
	public double calcul(){
		if (fStang == null)
			System.exit(1);
		return calcul(fStang.calcul());
	}
	
	public String derivare(){
	if (getfStang() == null)
		System.exit(1);
	return Produs.concatTermens(getfStang().derivare(),
			Cat.concatTermens("-1", Produs.concatTermens(Sin.concatTermeni(getfStang().toString()),
					Sin.concatTermeni(getfStang().toString()))));
			}
	
	public double calculDerivata(){
		if (getfStang() == null)
			System.exit(1);
		return Produs.Calcul(getfStang().calculDerivata(), Cat.Calcul(-1, 
				Produs.Calcul(Sin.calcul(getfStang().calculDerivata()), Sin.calcul(getfStang().calculDerivata()))));
		}
	public String toString(){
		if (getfStang() == null)
			System.exit(1);
		return concatTermeni(getfStang().toString());
	}
	public static String concatTermens(String aux1){
		String aux;
		int nrP;
		nrP = aux1.charAt(0) == '(' ? 0 : 2;
		aux = "ctg";
		if (nrP != 0) aux += "(";
			aux += aux1;
		if (nrP != 0) aux += ")";
			return aux;
	}
	public String concatTermeni(String aux1){
		String aux;
		int nrP;
		nrP = aux1.charAt(0) == '(' ? 0 : 2;
		aux = "ctg";
		if (nrP != 0) aux += "(";
		aux += aux1;
		if (nrP != 0) aux += ")";
		return aux;
	}
	public double calculeazaValoare() {
		return this.calcul();
	}

}
